<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/static/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
 <meta name="viewport" content="width=device-width" />
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
 <title>后台管理--角色列表</title> 
 <link href="${ctxStatic}/ligeruilib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css">
 <link href="${ctxStatic}/layui/css/layui.css" rel="stylesheet" />
 <link href="${ctxStatic}/css/kpiuitanchu.css" rel="stylesheet" />
 <script src="${ctxStatic}/js/jquery-1.8.3.min.js?v=2.0" type="text/javascript"></script>
 <script src="${ctxStatic}/layui/layui.all.js"  type="text/javascript"></script>
 <script src="${ctxStatic}/ligeruilib/ligerUI/js/core/base.js" type="text/javascript"></script>
 <script src="${ctxStatic}/ligeruilib/ligerUI/js/plugins/ligerTree.js" type="text/javascript"></script>
    <script src="${ctxStatic}/js/common.js" type="text/javascript"></script>

</head>
<body>
 <div class="tanchucontent" style="padding:0">
<div class="layui-tab layui-tab-brief" lay-filter="tabcontent">
  <ul class="layui-tab-title">
    <li lay-id="2" class="layui-this">可操作菜单</li>
    <li lay-id="3">可访问数据</li>
  </ul>
  <div class="layui-tab-content">
    <div class="layui-tab-item layui-show">
      <div style="width:100%;text-align: center;margin-top:5px;">
       <input type="button" class="button"  value="保存" id="btnsave" onclick="SaveMenu()" />
       <input type="button" class="button"  value="关闭" onclick="top.CloseOpenWindow()" />
      </div>
      <div id="menutree" style="height:350px;overflow-y:auto "></div>
    </div>
    <div class="layui-tab-item">
      <div style="width:100%;text-align: center;margin-top:5px;">
       <input type="button" class="button"  value="保存" id="btnsave" onclick="SaveOrg()" />
       <input type="button" class="button"  value="关闭" onclick="top.CloseOpenWindow()" />
      </div>
      <div style="color:#ffffff;width:430px">
      <div class="layui-form" >
      数据范围： <input type="radio" lay-filter="datafw" name="datafw" value="0" title="未设置" checked="">
              <input type="radio" lay-filter="datafw" name="datafw" value="1" title="全部数据">
              <input type="radio" lay-filter="datafw" name="datafw" value="2" title="自定义数据" >
      </div></div>
     <div id="orgtree" style="height:320px;overflow-y:auto "></div>
    </div>
  </div>
</div>
</div>

<input id="hidroleid" type="hidden" value="${roleid }">

<script>

layui.use('form', function(){
    form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
    form.on('radio(datafw)', function(data){ 
    	if(data.value==1){
    		selectAllNode(true);
    	}
    	else{
    		selectAllNode(false);
    	}
      })
	   form.render();
	});  

  var menutree=null,orgtree=null;
  $(function(){
	  $("#menutree").ligerTree({  
          url:'get_menu_list?roleid='+$("#hidroleid").val(), 
          idFieldName :'menuid',
          parentIDFieldName :'parentid',
          textFieldName:'menuname',
          nodeWidth:660,
          slide: false,
          enabledCompleteCheckbox:false
       });
	  menutree = $("#menutree").ligerGetTreeManager();
	  
	  
	  $("#orgtree").ligerTree({  
          url:'get_org_list?roleid='+$("#hidroleid").val(), 
          idFieldName :'orgid',
          parentIDFieldName :'orgparentid',
          textFieldName:'orgname',
          nodeWidth:660,
          slide: false
          //,single:true
          ,onCheck:function(){
        	  return false;
          }
          ,enabledCompleteCheckbox:true
       });
	  orgtree = $("#orgtree").ligerGetTreeManager();
  })
  
  
  
	function selectAllNode(flag) {
		var parm = function() {
			return flag;
		};
		if (flag==true) {
			orgtree.selectNode(parm);
		} else {
			orgtree.reload();
			//orgtree.selectNode(parm);
		}

	}

	function SaveMenu() {
		var notes = menutree.getChecked();
		var menuids = '';
		for (var i = 0; i < notes.length; i++) {
			menuids += notes[i].data.menuid + ",";
		}

		if (menuids == '') {
			alert('请选择菜单');
			return;
		}
		var roleid = $("#hidroleid").val();
		top.frames["iframe"].vRole.addrolemenu(roleid, menuids);
	}

	function SaveOrg() {
		var notes = orgtree.getChecked();
		var orgids = '';
		for (var i = 0; i < notes.length; i++) {
			orgids += notes[i].data.orgid + ",";
		}

		if (orgids == '') {
			alert('请选择机构');
			return;
		}
		var roleid = $("#hidroleid").val();
		top.frames["iframe"].vRole.addroleorg(roleid, orgids);
	}
</script>
</body>
</html>